/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package controller;

import java.util.Scanner;
import model.Course;
import model.Student;

/**
 *
 * @author Phillipp
 */
public class ConsoleManagement {
    static Studentmanagement studentmanagement = new Studentmanagement();
    public static void main(){
        boolean correctInput;
        Scanner console = new Scanner(System.in);
        
        System.out.println("Welcome to ESAT!"); 
        
        do{
            correctInput = true;
            System.out.println("Please enter the corresponding number");
            System.out.println("1: Navigate to Students");
            System.out.println("2: Navigate to Courses");
            System.out.println("3: Navigate to Universities");
            System.out.println("4: Navigate to Semester Abroad");
            
            String input = console.nextLine();
                  
                
                switch(input){
                    case "1": students(console);
                        break;
                    case "2": courses(console);
                        break;
                    case "3": System.out.println("Please try a different number.");
                        correctInput = false;
                        break;
                    case "4": System.out.println("Please try a different number.");
                        correctInput = false;
                        break;
                    default : System.out.println("Incorrect Input");
                        correctInput = false;
                        break;
                }
        }while(!correctInput);
        
        
        
       }
    private static void students(Scanner console){
        System.out.println("You are now here: Students");
        System.out.println("What do you want to do next?");
        System.out.println("1 : View students");
        System.out.println("2 : Create a student");
        System.out.println("3 : Go back to start");
        
        
       boolean correctInput;
       do{
        correctInput  = true;
        String enter = console.nextLine();
        switch(enter){
            case "1": //viewStudents(console, studentmanagement); not disyplaying correclty. But students are saved in xml!
                students(console);
                break;
            case "2": registerStudent(console);
                students(console);
                break;
            case "3": main();
            default : System.out.println("Incorrect Input");
                correctInput = false;
                break;
        }
       }while(!correctInput);
        
    }
    
    private static void viewStudents(Scanner console, Studentmanagement studentmanagement){
        System.out.println("List of students:"); 
        for(int i = 0; i < studentmanagement.getStudents().length; i++){
            if(studentmanagement.getStudents()[i] != null){
            System.out.println(studentmanagement.getStudents()[i].getStudentFirstName() + " " + studentmanagement.getStudents()[i].getStudentLastName());
            }
        }
    }
    
    private static void registerStudent(Scanner console){
        String firstName, lastName,title, sem, gender, studies, degree, officialAdress, currentAdress, email, phoneNumber, matriculationNumber;
        String dateOfBirth;
        
        System.out.println("Please enter the following information:");
        
        System.out.println("Students last name");
        lastName = console.nextLine();
        
        System.out.println("Students firstName");
        firstName = console.nextLine();
        
        System.out.println("Students title");
        title = console.nextLine();
        
        System.out.println("Students gender");
        gender = console.nextLine();
        
        System.out.println("Students officialAdress");
        officialAdress = console.nextLine();
        
        System.out.println("Students e-mail Adress");
        email = console.nextLine();
        
        System.out.println("Students phonenumber");
        phoneNumber = console.nextLine();
        
        System.out.println("Students matriculation number");
        matriculationNumber = console.nextLine();
        
        System.out.println("Students date of birth");
        dateOfBirth = console.nextLine();
        
        System.out.println("Students current adress");
        currentAdress = console.nextLine();
        
        System.out.println("Students number of semester");
        sem = console.nextLine();
        int semester = Integer.parseInt(sem);
        
        System.out.println("Studens field of studies");
        studies = console.nextLine();
        
        System.out.println("Students degree");
        degree = console.nextLine();
                
        System.out.println("Save student...");
        Student s = new Student(firstName, lastName, title, gender, officialAdress, currentAdress, email, phoneNumber, matriculationNumber, null, studies, semester, degree);
        
        try{
        s.saveStudent(firstName, lastName, title, gender, officialAdress, currentAdress, email, phoneNumber, matriculationNumber, null, gender, semester, gender);
        System.out.println("Saving completed!");
        }catch(Exception e){
            System.out.println("Error while saving!");
        }
        
    }
    
    private static void courses(Scanner console){
        System.out.println("You are now here: Courses");
        System.out.println("What do you want to do next?");
        System.out.println("1 : View courses");
        System.out.println("2 : Create a course");
        System.out.println("3 : Go back to start");
        
        
       boolean correctInput;
       do{
        correctInput  = true;
        String enter = console.nextLine();
        switch(enter){
            case "1": registerCourse(console);
                courses(console);
                break;
            case "2": 
                courses(console);
                break;
            case "3": main();
            default : System.out.println("Incorrect Input");
                correctInput = false;
                break;
        }
       }while(!correctInput);
    }
    
    private static void viewCourses(Scanner console){
        
    }
    
    private static void registerCourse(Scanner console){
        String coursename, courseDescription, coursetype, credits;
       
        System.out.println("Please enter the following information:");
        
        System.out.println("Coursename");
        coursename = console.nextLine();
        
        System.out.println("Course description");
        courseDescription = console.nextLine();
        
        System.out.println("Course type");
        coursetype = console.nextLine();
        
        System.out.println("Creditpoints");
        credits = console.nextLine();
        int cp =-1;
        try{
        cp = Integer.parseInt(credits);
        }
        catch(Exception e){
         System.out.println("Invalid input!");   
        }
        
        System.out.println("Save course...");
        
        Course c = new Course(coursename, cp, courseDescription, coursetype);
        
        try{
          c.saveCourse(coursename, cp, courseDescription, coursetype);
          System.out.println("Saving completed!");
        }
        catch(Exception e){
            System.out.println("Error while saving!");
        }
    }
    
    private static void viewSemesterAbroad(Scanner console){
        
    }
    
    private static void createSemesterAbroad(Scanner console){
        
    }
}
